package com.yuexiang.melodyhub.authserver.config;

import com.yuexiang.melodyhub.authserver.handler.*;
import com.yuexiang.melodyhub.authserver.handler.context.LoginContext;
import com.yuexiang.melodyhub.authserver.handler.context.RegisterContext;
import com.yuexiang.melodyhub.common.handler.AbstractValidationHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ValidationChainConfig {
    @Bean("loginValidationChain")
    public AbstractValidationHandler<LoginContext> loginValidationChain(
            CaptchaValidationHandler captchaHandler,
            UserLookupHandler userLookupHandler,
            UserStatusValidationHandler statusHandler,
            TokenGenerationHandler tokenHandler) {
        return captchaHandler
                .setNext(userLookupHandler
                        .setNext(statusHandler
                                .setNext(tokenHandler)));
    }

    @Bean("registerValidationChain")
    public AbstractValidationHandler<RegisterContext> registerValidationChain(
            EmailValidationHandler emailHandler,
            PasswordValidationHandler passwordHandler,
            CodeValidationHandler codeHandler) {
        return emailHandler
                .setNext(passwordHandler
                        .setNext(codeHandler));
    }
}
